package sky.service.Impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import sky.dao.AbstractDAO;
import sky.domain.ModelObject;
import sky.service.AbstractService;
import sky.tro.finders.AbstractFinder;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Gauss
 * Date: 20.10.13
 * Time: 15:49
 * To change this template use File | Settings | File Templates.
 */
@Service
public abstract class AbstractServiceImpl<T extends ModelObject> implements AbstractService<T> {

    //AbstractDAO<T> abstractDAO = getDAO();

    protected abstract AbstractDAO<T> getDAO();

    @Override
    @Transactional
    public void add(T t) {
        getDAO().add(t);
    }

    @Override
    @Transactional
    public void edit(T t) {
        getDAO().edit(t);
    }

    @Override
    @Transactional
    public void remove(Integer id) {
        getDAO().remove(id);
    }

    @Override
    @Transactional
    public List<T> list() {
        return getDAO().list();
    }

    @Override
    @Transactional
    public T getById(Integer id) {
        return getDAO().getById(id);
    }

    @Override
    @Transactional
    public T getByName(String name, Boolean isInitialize) {
        return getDAO().getByName(name, isInitialize);
    }

    @Override
    @Transactional
    public List<T> listByFinder(AbstractFinder finder) {
        return getDAO().listByFinder(finder);
    }
}
